﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using WFNetLib.StringFunc;

namespace 生命体征测试仪
{
    public partial class formMedicalResult : formBase
    {
        MedicalResultData result;
        public formMedicalResult(MedicalResultData m)
        {
            InitializeComponent();
            result = m;
        }

        private void formMedicalResult_Load(object sender, EventArgs e)
        {
            leftTime = 60;
            lbName.Text = formMain.curUser.Name+"于"+result.Time.ToString("yyyy年MM月dd日HH时mm分ss秒")+"的体检记录";
            if (!SysConfig.bHaveShenGao)
                medicalTab.TabPages.RemoveByKey("tabShenGaoTiZhong");
            if (!SysConfig.bHaveTiWen)
                medicalTab.TabPages.RemoveByKey("tabErWen");
            if (!SysConfig.bHaveXueYa)
                medicalTab.TabPages.RemoveByKey("tabXueYa");
            if (!SysConfig.bHaveXinDian)
                medicalTab.TabPages.RemoveByKey("tabXinDian");
            if (!SysConfig.bHaveXueYang)
                medicalTab.TabPages.RemoveByKey("tabXueYang");
            if (!SysConfig.bHaveXueZhi)
                medicalTab.TabPages.RemoveByKey("tabXueZhi");
            if (!SysConfig.bHaveXueTang)
                medicalTab.TabPages.RemoveByKey("tabXueTang");
            if (!SysConfig.bHaveZhiFangYi)
                medicalTab.TabPages.RemoveByKey("tabZhiFang");
            if (medicalTab.TabPages.Count == 0)
            {
                this.Close();
                return;
            }
            medicalTab.SelectTab(0);
            lShenGao.Text = result.ShenGao.ToString("F1");
            lTiZhong.Text =result.TiZhong.ToString("F2");
            ErWenResult.Text = result.ErWen.ToString("F1");
            lGaoYa.Text = result.GaoYa.ToString();
            lDiYa.Text = result.DiYa.ToString();
            lXinLv.Text = result.XinLv.ToString();
            XinDianAnalyseResult r = (XinDianAnalyseResult)result.XinDianResult;
            XinDianResult.Text = "分析结果为:" + r.ToString() + ",心率值为:" + result.XinDianXinLv.ToString();
            //画图
            if (result.XindianDatas != "")
            {
                ushort[] x = StringsFunction.strToHexushort(result.XindianDatas, "");
                int max=x.Max<ushort>();
                if (max > 255)
                {
                    chart1.ChartAreas[0].AxisY.Maximum = 4095;
                    chart2.ChartAreas[0].AxisY.Maximum = 4095;
                    chart3.ChartAreas[0].AxisY.Maximum = 4095;
                }
                else
                {
                    chart1.ChartAreas[0].AxisY.Maximum = 255;
                    chart2.ChartAreas[0].AxisY.Maximum = 255;
                    chart3.ChartAreas[0].AxisY.Maximum = 255;
                }
                for (int i = 0; i < x.Length;i++ )
                {
                    if (chart1.Series[0].Points.Count < 1675)
                    {
                        chart1.Series[0].Points.AddY(x[i]);
                    }
                    else if (chart2.Series[0].Points.Count < 1675)
                    {
                        chart2.Series[0].Points.AddY(x[i]);
                    }
                    else
                    {
                        chart3.Series[0].Points.AddY(x[i]);
                    }
                }
            }
            XueYang_spo2.Text = result.SpO2.ToString();
            XueYang_PR.Text = result.PR.ToString();
            XueYang_PI.Text = (((float)result.PI)/10).ToString("F1");

            XueTangResult.Text = result.XueTang1.ToString("F1");
            XueTangResult2.Text = result.XueTang2.ToString("F1");
            XueNiaoSuanResult.Text = result.NiaoSuan.ToString("F1");
            DanGuChunResult.Text = result.DanGuChun.ToString("F1");
            ZhiFang_Result.Text = "您的测试结果为!";
            ZhiFang_Result.Text += "脂肪:" + result.ZhiFang.ToString("F1") + "%,";
            ZhiFang_Result.Text += "BMI:" + result.BMI.ToString("F1") + ",";
            ZhiFang_Result.Text += "新陈代谢:" + result.XinChenDaiXie.ToString() + "Kcal,";
            ZhiFang_Result.Text += "体质:" + ((ZhiFang_TiZhi)result.TiZhi).ToString() + ",";
            ZhiFang_Result.Text += "体形:" + ((ZhiFang_TiXing)result.TiXing).ToString();
            lYaoWei.Text = result.YaoWei.ToString("F1");
            lTunWei.Text = result.TunWei.ToString("F1");
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            formReport f = new formReport(result);
            f.ShowDialog();
            this.Close();
        }

        int leftTime;
        private void timer1_Tick(object sender, EventArgs e)
        {
            leftTime--;
            if (leftTime == 0)
                this.Close();
            else
                skinLabel1.Text = leftTime.ToString();
        }

        private void medicalTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            leftTime = 60;
        }
    }
}
